package giit.computerbase.dao;

/**
 * This class is for connection SQLServer database<br>
 * User: tum0r
 * Package Name: giit.computerbase.dao
 * Time: 2018/10/28 Sunday 18:07:00
 */

import java.sql.DriverManager;
import java.sql.SQLException;

public class SQLServer extends SQL {

    public SQLServer() throws ClassNotFoundException {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    }

    @Override
    public boolean open(String host, int port, String dabaseName, String encode, String userName, String password) {
        StringBuffer url = new StringBuffer();
        url.append("jdbc:sqlserver://");
        url.append(host);
        url.append(":");
        url.append(String.valueOf(port));
        url.append(";DatabaseName=");
        url.append(dabaseName);

        try {
            connection = DriverManager.getConnection(url.toString(),userName,password);
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

}
